home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-04-30 | 35.5 KB | 775 lines | [TEXT/MPS ] |
- {[j=20/53/1$]}
-
- UNIT UFracApp;
-
- {-------------------------------------------------------------------------------------------
-
- Program: FracApp 2.0
- Unit: UFracApp
- File: UFracApp.p
- Includes: UFracApp.inc1.p
-
- by Keith Rollin & Bo3b Johnson
- of Apple Macintosh Developer Technical Support
-
- Copyright © 1988-1990 Apple Computer, Inc.
- All rights reserved.
-
- --------------------------------------------------------------------------------------------
-
- Main unit for FracApp 2.0. It defines the following classes:
-
- TFracAppApplication - Handles creation of documents, Windows menu, idle time
- munging, and multipaging.
- TPICTDocument - Sort of a generic PICT handling document. It’s supposed to be
- all-purpose, but I admit that it was created with FracApp in mind, so you
- might not be able to just drop it into your application without some changes.
- Anyway, it knows how to read and write a PICT file. All you have to do is
- sub-class it and override the DoDrawPicture method to do the actual imaging.
- You might also want to override DoRead and DoWrite to deal with any PICT
- header information you may have.
- TFracAppDocument - Sub-Class of TPICTDocument. Reads and writes PICT header
- information that describes the fractals we make. Also manages the FracApp
- engines we use to create the fractals in the first place. Finally, it acts as
- a go-between for the TFracAppView, and the engine that is generating our
- data.
- TFracAppWindow - Calls the application to tell it when windows are being added
- or removed. This is so we can have a Windows menu (very necessary when you
- have an application that makes all its windows as large as your screen.) Also
- repositions items in the info bars when the window changes size. This
- wouldn’t be necessary if MacApp had location determiners to go along with its
- size determiners.
- TFracAppView - CopyBits stuff from our offscreen pixmap to the window. Handles
- creation of new documents based on the selection, as the View keeps track of
- the selection rectangle. Also deals with highlighting the selection, and
- writing that selection to scrap on a Copy.
- TFracAppEngine - Base class for a fractal generating engine. Again, this was
- myopically designed with FracApp in mind, so you may have a chore of adopting
- it for Fractals other than the Mandelbrot set. It provides a core routine for
- calculating the value of a pixel, and defines methods you should override.
- The methods define what should be done at Idle time, and how to read and
- write Engine specific data to disk.
- TNormalFracAppEngine - Calculates the entire document pixel-by-pixel.
- TFastFracAppEngine - Calculates the Mandelbrot set using the Mariani/Silver
- algorithm. This algorithm assumes that the content of any area that is
- bounded by a single color is the same color. This algorithm recursively
- divides the document up into 4 parts, and examines the borders of each
- rectangle. If the border is all the same color, then the entire rectangle is
- filled with that color, and we go to the next rectangle. If the border colors
- are not all the same, then THAT rectangle is quartered, and we do the process
- again.
-
- --------------------------------------------------------------------------------------------}
-
- INTERFACE
-
- USES UMacApp, UDialog, UPrinting, PaletteMgr, Resources, ToolUtils, Packages,
- QDOffscreen, SANE, Timer, UOffscreen, UAreaSelector, URectStack;
-
- CONST
-
- { Constants used for identification }
-
- kSignature = 'Arfz'; { Application signature }
- kHeaderID = $4641; { Header ID = ‘FA’ for FracApp }
- kFileType = 'PICT'; { File-type code used for document files
- created by this application }
-
- kSelPattern = 128; { pattern resource Id. This is in the public section
- as both UFracApp and UAreaSelector access the pattern. }
-
- TYPE
-
- { The following record is used to define data in two places. First of all, it
- is included in the set of data that defines a fractal document, and is saved
- to disk in the PICT header part. It is also used for a global variable that
- we use when creating a new document during a zoom or multipage operation; it
- contains the minimum amount of information for creating a new fractal
- document. }
-
- PageRecord = RECORD
- RealMin: Extended; { 12 These are valid for any doc }
- RealMax: Extended; { 12 }
- ImagMin: Extended; { 12 }
- ImagMax: Extended; { 12 }
- multiPaging: Boolean; { 2 Whether or not we are multipaging }
- currentH: Integer; { 2 only make sense if above is TRUE }
- currentV: Integer; { 2 These two hold the current page }
- maxH: Integer; { 2 These two hold the range of pages }
- maxV: Integer; { 2 }
- END; { 58 for PageRecord }
-
- { The header record for each of the files saved by FracApp. This header
- includes the pertinent data that allows a fractal to be restarted, as well as
- displayed on the screen. }
-
- FracRecord = RECORD
- fType: OSType; { 4 set as ‘Arfz’ for these documents. }
- hdrId: Integer; { 2 ‘FA’ - FracApp header ID. }
- version: Integer; { 2 file version decides type of file. }
- done: Boolean; { 2 if the fractal is finished or not. }
- elapsed: Longint; { 4 time in msec taken so far. }
- startingTime: Longint; { 4 result from GetDateTime (secs) }
- endingTime: Longint; { 4 result from GetDateTime (secs) }
- areaComplete: Longint; { 4 amount of the fractal completed }
- use32BitCQD: Boolean; { 2 Kind of offworlder to use. }
- pages: PageRecord; { 58 holds info on the current page }
- deltaP: Extended; { 12 horz step size in fractal space. }
- deltaQ: Extended; { 12 vert step size in fractal space. }
- plotWidth: Longint; { 4 width of fractal area in pixels. }
- plotHeight: Longint; { 4 height of fractal area in pixels. }
- calcRect: Rect; { 8 rectangle surrounding the window it
- was built for. }
- END; {126 FracRecord. }
-
- {------------------------------- Application -------------------------------}
-
- TFracAppApplication = OBJECT (TApplication)
-
- fWindowList: TList; { Private - Holds the list of windows
- in the order in which they were
- created. Maintained by
- InstallWindowMenuItem }
-
- PROCEDURE TFracAppApplication.IFracAppApplication(itsMainFileType: OSType);
- { Initializes the application and globals. Called by the main application when
- the applicaton object is created. }
-
- PROCEDURE TFracAppApplication.AutoSaveThisGuy(doneDoc: TFracAppDocument);
- { Handy dude for saving and closing a document without human accompaniament.
- We use this when creating a series of documents, possibly at night when
- no one is around. Called by TFracAppApplication.DoIdle when a document
- signals that it’s done. }
-
- PROCEDURE TFracAppApplication.BuildWindowsMenu;
- { Called by TFracAppApplication.DoSetupMenus whenever our Windows menu changes
- and needs to be rebuilt. }
-
- PROCEDURE TFracAppApplication.Close; OVERRIDE;
- { Called by MacApp when the user selects Quit. Tear down stuff when the program
- is about to quit. Most importantly, we have to turn off the time manager
- routines. Done here rather than in TApplication.Free, as .Free rarely gets
- called. It’s up to the main application to do that, and we’ve never
- recommended that that be done. }
-
- PROCEDURE TFracAppApplication.CreateManyColors;
- { Called by IFracAppApplication to initialize our color Palettes. }
-
- FUNCTION TFracAppApplication.DoIdle(Phase: IdlePhase): Boolean; OVERRIDE;
- { Called by MacApp to perform Idle time processing for the application. This
- will do the fractal calculation during the idle times. Also allows the
- topmost document a chance to to color animation. }
-
- FUNCTION TFracAppApplication.DoMakeDocument(itsCmdNumber: CmdNumber):
- TDocument; OVERRIDE;
- { Launches a TFracAppDocument; called when application’s icon is opened, or
- when New, New From Selection, New MultiPage, or Open is requested by the
- user. Every application which uses documents MUST override this method. }
-
- FUNCTION TFracAppApplication.DoMenuCommand(aCmdNumber: CmdNumber): TCommand;
- OVERRIDE;
- { Called by MacApp when a menu item has been chosen. Handles executing Animate,
- 32-Bit Color QuickDraw, and 300 dpi options. }
-
- PROCEDURE TFracAppApplication.DoSetupMenus; OVERRIDE;
- { Called by MacApp when the user clicks on the menu. Handles the en/disabling
- of Animate, 32-Bit Color QuickDraw, and 300 dpi options. }
-
- PROCEDURE TFracAppApplication.DoShowAboutApp; OVERRIDE;
- { Shows the About Box. With MacApp 2.0, this method is called from a
- TAboutCommand when the user selects the About… item. }
-
- PROCEDURE TFracAppApplication.DoWindowsCommand(aCmdNumber: CmdNumber);
- { Sub-method to handle selections in the Windows menu. Called by
- TFracAppApplication.DoMenuCommand. }
-
- PROCEDURE TFracAppApplication.InstallWindowMenuItem(window: TWindow;
- install: Boolean);
- { Called by our TFracAppWindow object when it shows or hides itself. This
- method keeps track of the window in a list, which is used for building
- our Windows menu. }
-
- PROCEDURE TFracAppApplication.MakeNewGibbleyFromGPageRecord;
- { Handy routine for when we are multipaging. It is called from our DoIdle
- method to create a new document based on the state of the last one. }
-
- PROCEDURE TFracAppApplication.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: Integer));
- OVERRIDE;
-
- END; { TFracAppApplication }
-
- {------------------------------- Document -------------------------------}
-
- TPICTDocument = OBJECT (TDocument)
-
- PROCEDURE TPICTDocument.IPICTDocument;
- { Init routine for the document. For TPICTDocument, it does nothing except call
- IDocument. }
-
- PROCEDURE TPICTDocument.DoDrawPicture;
- { DoNeedDiskSpace and DoWrite need some way to image the picture. A
- TPICTDocument doesn’t have any idea how the data is being kept, so it doesn’t
- know how to do the imaging. Therefore, we have this DoDrawPicture method that
- should be overridden by subclasses. It is the subclasses that know how the
- data is stored, and so they can image it. By default, this routine does
- nothing but complain. }
-
- PROCEDURE TPICTDocument.DoNeedDiskSpace(VAR dataForkBytes,
- rsrcForkBytes: Longint); OVERRIDE;
- { Called by MacApp when preparing to write out a disk file. Finds out the
- entire size of the object to be saved into the file so that the correct
- amount of disk space can be used. For a TPICTDocument, this is the size of
- the PICT, plus 512 bytes for the header. }
-
- PROCEDURE TPICTDocument.DoRead(aRefNum: Integer; rsrcExists,
- forPrinting: Boolean); OVERRIDE;
- { Called by MacApp to read the data from the data fork of the file. Stows it
- into the document’s bitMap. This bitmap should be setup by the subclass in
- its DoRead method before calling this INHERITED method. In other words, this
- just draws into the current port and device. }
-
- PROCEDURE TPICTDocument.DoWrite(aRefNum: Integer; makingCopy: Boolean); OVERRIDE;
- { Called by MacApp to write out the document’s data. Converts the data in the
- document’s port into a PICT, then writes that block out to the file, making
- it into a standard PICT file. It does this with the help of its humbler
- servant, TPICTDocument.DoDrawPicture. }
-
- PROCEDURE TPICTDocument.SetRWGrafProcs(VAR oldProcs: QDProcsPtr;
- VAR newProcs: CQDProcs; readProc,
- writeProc: ProcPtr);
- { Common routine to set the current port’s grafprocs for reading and writing.
- It gets called by our DoRead and DoWriter overrides to that we can read
- and write PICTs without causing a big memory hit. }
-
- PROCEDURE TPICTDocument.Fields(PROCEDURE
- DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: Integer)); OVERRIDE;
-
- END;
-
- TFracAppDocument = OBJECT (TPICTDocument)
-
- fFracHeader: FracRecord; { Global state of any fractal. It can be
- accessed with the following methods:
- GetDone, GetFracHeader, GetPlotHeight,
- GetPlotWidth }
- fFracAppEngine: TFracAppEngine; { Private - Used by CalcTown, DoRead, and
- DoWrite }
- fFracAppWindow: TFracAppWindow; { Private - Used to animate the window’s
- palettes. }
- fOffWorlder: TOffscreen; { Private - Object that handle offscreen
- management. }
- fStartupMode: CmdNumber; { Private - Used in DoInitialState to set
- variables that are different depending
- on whether we are multipaging or not,
- or if we are creating this document
- afresh or based on the selection of
- another document. }
-
- PROCEDURE TFracAppDocument.IFracAppDocument(use32BitCQD: Boolean;
- startupMode: CmdNumber);
- { Init routine for the document. Called when the new document is created in
- TFracAppApplication.DoMakeDocument. Sets up the object, then the fractal
- default state. }
-
- PROCEDURE TFracAppDocument.Free; OVERRIDE;
- { Free method for our document. It calls FreeData to dispose the data block of
- the picture data that was read in from the disk, and kills the offscreen
- stuff. }
-
- PROCEDURE TFracAppDocument.AnimateColors;
- { Called by the application at Idle time to do the palette animation. }
-
- PROCEDURE TFracAppDocument.BumpAreaComplete(areaAmount: Longint);
- { Adds “areaAmount” to the areaComplete field. We keep track of this stuff so
- that we can display the percentage complete. This is my own method that the
- TFracAppEngines call when they’ve updated a new area of the fractal. }
-
- PROCEDURE TFracAppDocument.BumpChangeCount;
- { Increments the fChangeCount field. This is my own method that the
- TFracAppEngines call when they’ve updated a new area of the fractal. }
-
- PROCEDURE TFracAppDocument.BumpCalculationTime(elapsedAmount: Longint);
- { Increments the elapsedTime field and updates the window display. Called
- by the document idling routine: CalcTown. }
-
- FUNCTION TFracAppDocument.CalcTown: Boolean;
- { Document’s idling routine. Called by TFracAppApplication.DoIdle when it’s
- this document’s turn to calculate part of itself. Takes care of calling the
- TFracAppEngine, and updating the window timer displays. }
-
- PROCEDURE TFracAppDocument.DoDrawPicture; OVERRIDE;
- { Called by TPICTDocument.DoRead and DoWrite. Images the picture for saving to
- disk. Just calls Copybits. }
-
- PROCEDURE TFracAppDocument.DoInitialState; OVERRIDE;
- { Called by MacApp if we are making a new document (as opposed to reading one
- from disk). Does the work for a New operation, where we start with a new
- fractal that doesn’t have any stored data. }
-
- PROCEDURE TFracAppDocument.DoMakeViews(forPrinting: Boolean); OVERRIDE;
- { Called when launching a new document, be it newly created or being read from
- disk. Launches the view which is seen in the document’s window. Every
- document which has any screen display or which can be printed MUST override
- this method. }
-
- FUNCTION TFracAppDocument.DoMenuCommand(aCmdNumber: CmdNumber): TCommand;
- OVERRIDE;
- { Called by MacApp when a menu item has been chosen. Handles the Copy menu
- item, as well as everything in the Zoomy menu }
-
- PROCEDURE TFracAppDocument.DoNeedDiskSpace(VAR dataForkBytes,
- rsrcForkBytes: Longint); OVERRIDE
- ;
- { Called by MacApp when preparing to save a document to disk. This override
- doesn’t do any calculations itself, but it does prepare the offscreen world
- before we call the INHERITED method. }
-
- PROCEDURE TFracAppDocument.DoRead(aRefNum: Integer; rsrcExists,
- forPrinting: Boolean); OVERRIDE;
- { Called by MacApp to read the data from the data fork of the file. Sets up the
- offscreen world so that we can call the INHERITED method to do the reading of
- the PICT. Also resets the vars in the document object to match the saved
- values from the header. }
-
- PROCEDURE TFracAppDocument.DoSetupMenus; OVERRIDE;
- { Called by MacApp when the user clicks on the menu. Handles the Copy menu
- item, as well as everything in the “Animate” menu. The “Animate” menu is only
- enabled if we have 32-bit Color QuickDraw. }
-
- PROCEDURE TFracAppDocument.DoWrite(aRefNum: Integer; makingCopy: Boolean); OVERRIDE;
- { Called by MacApp to write out the document’s data. Sets up the offscreen
- world, and calls the INHERITED method to actually write out the PICT. Also
- writes out the standard FracHeader, and calls the engine’s DoWrite method to
- have it write out anything it needs. }
-
- PROCEDURE TFracAppDocument.FreeData; OVERRIDE;
- { Free method usually used for Revert operation, kept here to show the normal
- Free approach. }
-
- FUNCTION TFracAppDocument.GetDone: Boolean;
- { Returns the fFracHeader.done field. Called by various FracApp routines to see
- if this document needs any calculation time. }
-
- FUNCTION TFracAppDocument.GetFracHeader: FracRecord;
- { Returns a copy of the fFracHeader field. This is an easy way for the
- TFracAppEngine to get a lot of working values it needs. }
-
- FUNCTION TFracAppDocument.GetFracPort: CGrafPtr;
- { Returns the offscreen port. Used by the TFracAppView when updating the screen. }
-
- FUNCTION TFracAppDocument.GetOffPixBase: Ptr;
- { Returns the pointer to the bits for the offscreen port. Called by the
- TFracAppEngine when doing its own version of GetCPixel. }
-
- FUNCTION TFracAppDocument.GetPlotHeight: Longint;
- { Returns fFracHeader.plotHeight. Called by TAreaSelector so that it knows what
- dimensions the document is, so that it can etch a proportional selection
- rectangle. }
-
- FUNCTION TFracAppDocument.GetPlotWidth: Longint;
- { Returns fFracHeader.plotWidth. Called by TAreaSelector so that it knows what
- dimensions the document is, so that it can etch a proportional selection
- rectangle. }
-
- FUNCTION TFracAppDocument.IsMultiPaging: Boolean;
- { Return TRUE if this document is one in a series of multi-paged documents. }
-
- PROCEDURE TFracAppDocument.JumblePalette;
- { Jumbles up the palette so that we get a nice banding effect. Called by
- TFracAppDocument.DoMenuCommand when the user selects the Jump Palette menu
- item. }
-
- PROCEDURE TFracAppDocument.LockThePixels(lockIt: Boolean);
- { Called by the TFracAppView before it does any CopyBits operations. This is
- so the View only needs to know about the TFracAppDocument; it never needs
- to know that a TOffScreen object exists. }
-
- FUNCTION TFracAppDocument.MakeFracAppEngine(version: Integer): TFracAppEngine
- ;
- { Handy utility for making a TFracAppEngine. Makes a different kind depending
- on what ‘version’ is set to. Called by TFracAppDocument.DoRead and
- DoInitialState. }
-
- FUNCTION TFracAppDocument.MakeOffWorlder(use32BitCQD: Boolean;
- bounds: Rect): TOffscreen;
- { Handy utility for making a TOffScreen. Makes a different kind depending on
- what ‘use32BitCQD’ is set to. Called by TFracAppDocument.DoRead and
- DoInitialState. }
-
- PROCEDURE TFracAppDocument.PreDraw;
- { Called by TFracAppEngine before it images to the offscreen bitmap. This is
- so the Engine only needs to know about the TFracAppDocument; it never needs
- to know that a TOffScreen object exists. }
-
- PROCEDURE TFracAppDocument.PostDraw;
- { Called by TFracAppEngine when it is all done imaging to the offscreen dude. }
-
- PROCEDURE TFracAppDocument.ReportRectCompleted(dirtyRect: Rect);
- { Called by the TFracAppEngine when an area of the fractal has been completed and
- needs to be copied to the screen. }
-
- PROCEDURE TFracAppDocument.RestorePalette;
- { Recovers from the effects of Animating or Jumbling. Called by
- TFracAppDocument.DoMenuCommand when the user selects “Everything back to
- Normal”, or turns off “Jumble Palette”. }
-
- PROCEDURE TFracAppDocument.SetAreaComplete(newComplete: Longint;
- forceUpdate: Boolean);
- { Updates the areaCompleted field in fFracHeader. Also updates the percentage
- field in the window. }
-
- PROCEDURE TFracAppDocument.SetCalculationTime(newElapsed: Longint;
- forceUpdate: Boolean);
- { Updates the elapsedTime field in fFracHeader. Also updates the calculation time
- field in the window’s infobar. }
-
- PROCEDURE TFracAppDocument.SetElapsedTime(forceUpdate: Boolean);
- { Updates the elapsed time field in the window’s infobar based on the starting
- and current time. }
-
- PROCEDURE TFracAppDocument.SetMethodName(forceUpdate: Boolean);
- { Sets the string that displays the algorithm being used to create the fractal.
- Called by TFracAppDocument.DoMakeViews when the document is being created. }
-
- PROCEDURE TFracAppDocument.SetVersion(version: Integer);
- { Called by the TFracAppEngine when it initializes itself. The engine is
- responsible for keeping track of what version document is created. Calling
- SetVersion is its way of informing the document what version it is. }
-
- PROCEDURE TFracAppDocument.StashSelectedRange;
- { Called by the routines that handle creating a new document based on the
- current selection Transfers information relating to the selection on the
- screen into some global variables. This is so we can create a new document
- from them. }
-
- PROCEDURE TFracAppDocument.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: Integer)); OVERRIDE;
-
- END; { TFracAppDocument }
-
- {------------------------------- Window -------------------------------}
-
- TFracAppWindow = OBJECT (TWindow)
-
- fFracAppView: TFracAppView;
- fCTimeLabelView: TStaticText;
- fCTimeView: TStaticText;
- fETimeLabelView: TStaticText;
- fETimeView: TStaticText;
- fMethodNameView: TStaticText;
- fPercentView: TStaticText;
- fPercentLabelView: TStaticText;
- fSingleBarView: TControl;
-
- PROCEDURE TFracAppWindow.IRes(itsDocument: TDocument; itsSuperView: TView;
- VAR itsParams: Ptr); OVERRIDE;
- { Initialize our window object. Overridden to set our instance variables to
- NIL. }
-
- PROCEDURE TFracAppWindow.AdjustInfoBar(width, height: VCoordinate;
- invalidate: Boolean);
- { Called by TFracAppWindow.Show and Resize to make sure the items in the
- infobar and the percentage complete label are all in the right places. }
-
- FUNCTION TFracAppWindow.GetCTimeView: TStaticText;
- { Return the “Calculation Time” text item. Called by TFracAppDocument when it
- needs to update that part of the display. }
-
- FUNCTION TFracAppWindow.GetETimeView: TStaticText;
- { Return the “Elapsed Time” text item. Called by TFracAppDocument when it needs
- to update that part of the display. }
-
- FUNCTION TFracAppWindow.GetFracAppView: TFracAppView;
- { Return the main view that displays the fractal. Called by TFracAppDocument
- when it needs to update that part of the display. }
-
- FUNCTION TFracAppWindow.GetMethodView: TStaticText;
- { Return the text item that shows the algorithm being used. Called by
- TFracAppDocument when it needs to initialize that part of the display. }
-
- FUNCTION TFracAppWindow.GetPercentView: TStaticText;
- { Return the “Percentage complete” text item. Called by TFracAppDocument when
- it needs to update that part of the display. }
-
- PROCEDURE TFracAppWindow.Open; OVERRIDE;
- { Called by MacApp when it needs to open a window. We override it here so that
- we can also call AdjustInfoBar. }
-
- PROCEDURE TFracAppWindow.Resize(width, height: VCoordinate;
- invalidate: Boolean); OVERRIDE;
- { Called by MacApp when it needs to resize a window. We override it here so
- that we can also call AdjustInfoBar. }
-
- PROCEDURE TFracAppWindow.Show(state, redraw: Boolean); OVERRIDE;
- { Called by MacApp when it shows or hides a window. Overridden so that we can
- add or delete ourselves from the Windows menu. }
-
- PROCEDURE TFracAppWindow.SetTitle(newTitle: Str255); OVERRIDE;
- { Overridden so that we can force the Windows menu to be rebuilt if this
- window’s name changes. This can happen when a document is saved. }
-
- PROCEDURE TFracAppWindow.Fields(PROCEDURE
- DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: Integer)); OVERRIDE;
-
- END;
-
- {------------------------------- View -------------------------------}
-
- { This object is used to display the elapsed time items, and the percentage
- complete item. I found that with a normal TStaticText item, I got too much
- flashing when I updated the strings. There was too much of a time gap between
- when the old string got erased, and the new one got drawn. I’ve tried to
- minimize that by having MATextbox (which is what ultimately draws the string)
- erase the old text when it draws the new. There is still SOME flicker, but
- not as much as there used to be. }
-
- TNoFlashStaticText = OBJECT (TStaticText)
-
- PROCEDURE TNoFlashStaticText.ImageText(text: Ptr;
- Length: LONGINT;
- box: Rect;
- just: INTEGER); OVERRIDE;
- { Overridden so that it passes the kEraseText parameter to MATextbox. }
-
- PROCEDURE TNoFlashStaticText.SetText(theText: Str255;
- redraw: BOOLEAN); OVERRIDE;
- { Overridden to inhibit erasing the old text before drawing the new. }
-
- PROCEDURE TNoFlashStaticText.Fields(PROCEDURE
- DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: Integer)); OVERRIDE;
- END;
-
-
- { This is the object that displays the fractal. Besides having its .Draw method
- overridden so that it can copybits the offscreen image, this View also keeps
- track of the current selection rectangle. Because of this, it also handles
- the menu items that would only be enabled when there is a selection. This
- includes Copy, New From Selection, and New Multi-Page. }
-
- TFracAppView = OBJECT (TView)
-
- fFracAppDocument: TFracAppDocument; { Private - Used to tell the document
- to do whatever is necessary to
- prepare the offscreen for updating of
- the window. Also used to tell the
- document to stash the selected range
- into the global page record. Although
- the view has the selected range, the
- document contains the necessary
- scalinging information. }
- fSelectionRect: Rect; { Rectangle that is current selection.
- You can get/set this rectangle with
- Get/SetSelection. }
-
- PROCEDURE TFracAppView.IRes(itsDocument: TDocument; itsSuperView: TView;
- VAR itsParams: Ptr); OVERRIDE;
- { Inits the view object itself. Keeps track of the document, and initializes
- the selection rect to be empty. }
-
- PROCEDURE TFracAppView.DoHighlightSelection(fromHL, toHL: HLState); OVERRIDE;
- { Called by MacApp’s updating routines to highlight the current selection
- rectangle if there is one. }
-
- FUNCTION TFracAppView.DoMenuCommand(aCmdNumber: CmdNumber): TCommand;
- OVERRIDE;
- { Called by MacApp when a menu item has been chosen. Handle the menu choices
- for New Fractal out of the File Menu, and the Copy and SelectAll commands
- from the Edit menu. }
-
- FUNCTION TFracAppView.DoMouseCommand(VAR theMouse: Point;
- VAR info: EventInfo;
- VAR hysteresis: Point): TCommand;
- OVERRIDE;
- { Called by MacApp to handle the mouse events in the view. Needs to do the
- selection of a new range for the next fractal to be calculated. }
-
- PROCEDURE TFracAppView.DoSetupMenus; OVERRIDE;
- { Called by MacApp when the user clicks on the menu. Set up the New Fractal
- menus choice in Fractal Menu, based on selection. }
-
- PROCEDURE TFracAppView.Draw(area: Rect); OVERRIDE;
- { Called by MacApp to draw the view seen in the window. Every nonblank view
- MUST override this method. }
-
- PROCEDURE TFracAppView.GetQDExtent(VAR qdExtent: Rect); OVERRIDE;
- { Overridden so that we can redefine the extent of the view when pasting to
- the scrap. Paul Snively Memorial Brace ---> }
-
- FUNCTION TFracAppView.GetSelection: Rect;
- { Returns the current selection rectangle. Called by
- TFracAppDocument.StashSelectedRange to get the information it needs to to
- help create a new document based on the current selection. }
-
- FUNCTION TFracAppView.HasSelection: Boolean;
- { Returns TRUE if there is a selection on the screen. Handy when we are
- enabling menu items based on whether or not there is a selection. }
-
- PROCEDURE TFracAppView.InvalidRect(r: Rect); OVERRIDE;
- { InvalidRect is a TView method that invalidates the specified part of the
- view. We override it here to add a little optimization. The ToolBox routine
- InvalRect does not optimize for when the passed rectangle is empty. Neither
- does MacApp. So we check for that here. }
-
- PROCEDURE TFracAppView.SetSelection(theSelectionRect: Rect; redraw: Boolean);
- { Sets and redraws the selection. }
-
- PROCEDURE TFracAppView.Fields(PROCEDURE
- DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: Integer)); OVERRIDE;
-
- END; { TFracAppView }
-
- {------------------------------- Engine -------------------------------}
-
- TFracAppEngine = OBJECT (TObject)
-
- fFracAppDocument: TFracAppDocument; { Private - Used to tell the document
- that new parts of the fractal have
- been completed, and that the window
- needs to be updated. }
- fFracHeaderCopy: FracRecord; { Private - Holds a copy of the STATIC
- parts of the FracHeader used by the
- FracAppDocument. }
-
- PROCEDURE TFracAppEngine.IFracAppEngine(itsDocument: TFracAppDocument);
- { Inits the engine object itself. Remembers a reference to its document, and
- makes a working copy of its FracHeader. This is done for speed so that we
- don’t have to continually query the document for its info. }
-
- FUNCTION TFracAppEngine.CalcCity: Boolean;
- { Abstract method for calculating a little bit of the fractal. Called by
- TFracAppDocument.CalcTown. This one here doesn’t do anything; it is meant to
- be overridden. }
-
- PROCEDURE TFracAppEngine.DoRead(aRefNum: Integer; rsrcExists,
- forPrinting: Boolean);
- { Abstract method for reading what the engine needs from disk. Called by
- TFracAppDocument.DoRead. This one here doesn’t do anything; it is meant to
- be overridden. }
-
- PROCEDURE TFracAppEngine.DoWrite(aRefNum: Integer; makingCopy: Boolean);
- { Abstract method for writing what the engine needs to disk. Called by
- TFracAppDocument.DoWrite. This one here doesn’t do anything; it is meant to
- be overridden. }
-
- PROCEDURE TFracAppEngine.FAGetCPixel(x, y: Integer; VAR itsRGB: RGBColor);
- { Normal Color QuickDraw has an annoying habit of hiding and showing the cursor
- when calling GetCPixel -- even for an offscreen pixmap. The bug has been
- fixed in 32-bit color QuickDraw. This method checks to see what system we are
- running under. If GetCPixel is OK, we call it. Otherwise, we do it by hand. }
-
- PROCEDURE TFracAppEngine.GoFigger(x, y, Po, Qo: Extended; M, K: Integer; VAR kol: Integer);
- { Heart and soul of the program. Called by the CalcCity routines to calculate
- the color of the specified point. This method is actually implemented in
- assembly. }
-
- PROCEDURE TFracAppEngine.ReportRectCompleted(dirtyRect: Rect);
- { Bottleneck used by CalcCity to inform the document that part of the fractal
- has been freshly calculated and needs to be copied to the screen. }
-
- PROCEDURE TFracAppEngine.PixWhap(col, row: Integer; VAR itsRect: Rect;
- VAR itsRGB: RGBColor);
- { Called by the engine’s CalcCity method. Given a point, figure out its color
- and plot it. Also returns the actual rectangle used for plotting the thing,
- and the color used. }
-
- PROCEDURE TFracAppEngine.Fields(PROCEDURE
- DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: Integer)); OVERRIDE;
-
- END;
-
- TNormalFracAppEngine = OBJECT (TFracAppEngine)
-
- fCurrentLocation: Point; { Private - holds current positon of the
- “pen”. }
-
- PROCEDURE TNormalFracAppEngine.INormalFracAppEngine(itsDocument:
- TFracAppDocument);
- { Initializes the TNormalFracAppEngine, as well as its superclass. Tells the
- document its version number, and initializes the pen to (0,0). }
-
- FUNCTION TNormalFracAppEngine.CalcCity: Boolean; OVERRIDE;
- { Calculates the fractal one pixel at a time. If we’ve calculated a whole row,
- tell the document so that it can copy it to the screen. }
-
- PROCEDURE TNormalFracAppEngine.DoRead(aRefNum: Integer; rsrcExists,
- forPrinting: Boolean); OVERRIDE;
- { Called by TFracAppDocument.DoRead. Reads fCurrentLocation from disk. }
-
- PROCEDURE TNormalFracAppEngine.DoWrite(aRefNum: Integer;
- makingCopy: Boolean); OVERRIDE;
- { Called by TFracAppDocument.DoWrite. Writes fCurrentLocation to disk. }
-
- PROCEDURE TNormalFracAppEngine.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: Integer));
- OVERRIDE;
-
- END;
-
- TFastFracAppEngine = OBJECT (TFracAppEngine)
-
- fRectStack: TRectStack; { Private - maintains the areas of the
- document we need to still calculate. }
-
- PROCEDURE TFastFracAppEngine.IFastFracAppEngine(itsDocument: TFracAppDocument
- );
- { Initializes the TFastFracAppEngine, as well as its superclass. Tells the
- document its version number, creates a TRectStack, and seeds it with 4
- starting rectangles. }
-
- PROCEDURE TFastFracAppEngine.Free; OVERRIDE;
- { Frees fRectStack. }
-
- FUNCTION TFastFracAppEngine.CalcCity: Boolean; OVERRIDE;
- { Calculates the fractal using the divide and conquer method. }
-
- PROCEDURE TFastFracAppEngine.DivideAndConquer(r: Rect);
- { Takes a rectangle, quarters it, and pushes it on the rect stack. Called by
- CalcCity when it finds a rectangle whose border is not all the same color. }
-
- PROCEDURE TFastFracAppEngine.DoRead(aRefNum: Integer; rsrcExists,
- forPrinting: Boolean); OVERRIDE;
- { Called by TFracAppDocument.DoRead. Reads the rect stack from disk. }
-
- PROCEDURE TFastFracAppEngine.DoWrite(aRefNum: Integer;
- makingCopy: Boolean); OVERRIDE;
- { Called by TFracAppDocument.DoWrite. Writes the rect stack to disk. }
-
- PROCEDURE TFastFracAppEngine.ReportRectCompleted(dirtyRect: Rect); OVERRIDE;
- { Bottleneck used by CalcCity to inform the document that part of the fractal
- has been freshly calculated and needs to be copied to the screen. We override
- it here to fix up the rectangle. Our rectangles are chosen so that there is a
- little bit of overlap between them and the rects next to them. We have to get
- rid of that overlap so that updating is more efficient, and so that our
- “areaCompleted” running total is accurate. }
-
- PROCEDURE TFastFracAppEngine.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: Integer)); OVERRIDE
- ;
-
- END;
-
- {$IFC NOT qPerform}
- VAR
- gCounter: Longint;
- {$ENDC}
-
- IMPLEMENTATION
-
- {$I UFracApp.inc1.p}
-
- END.
-